package com.app.taobao.wrapper;

import java.io.File;
import java.util.List;

import com.app.taobao.RequestTaoBao;
import com.taobao.api.ApiException;
import com.taobao.api.domain.ItemCat;
import com.taobao.api.response.ItemcatsGetResponse;
import com.taobao.api.response.ItempropsGetResponse;
import com.utils.UtilsFile;

public class RequestTaobaoWrapper {
	
	public void requestAndUpdateItemcats(Long parentCid, String storagePath) throws ApiException{
		RequestTaoBao req = new RequestTaoBao();
		ItemcatsGetResponse itemcatsGetRequest;
		itemcatsGetRequest = req.itemcatsGetRequest(parentCid);
		File file = new File(storagePath + "/" + parentCid + ".xml");
		UtilsFile.LogToFile2(file, itemcatsGetRequest.getBody(), false);
		List<ItemCat> itemCats = itemcatsGetRequest.getItemCats();
		for (ItemCat itemCat : itemCats) {
			ItempropsGetResponse itempropsGetRequest = req.itempropsGetRequest(itemCat.getCid());
			file = new File(storagePath + "/" +itemCat.getCid()+ ".xml");
			UtilsFile.LogToFile2(file, itempropsGetRequest.getBody(), false);
		}
	}
}
